//线程不安全的类
//    @Aspect
//    @Component
//    public class MyAspect {
//        // 是否安全?
//        private long start = 0L;
//
//        @Before("execution(* *(..))")
//        public void before() {
//            start = System.nanoTime();
//        }
//
//        @After("execution(* *( ..))")
//        public void after() {
//        long end = System.nanoTime();
//        System.out.println("cost time:"+(end-start));
//        }
//    }

//使用环绕通知实现线程安全
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

    @Aspect
    @Component
    public class MyAspect {

        @Around("execution(* *(..))")
        public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
            // 记录方法执行前的时间
            long start = System.nanoTime();

            try {
                // 继续执行原方法
                Object result = joinPoint.proceed();
                return result;
            } finally {
                // 方法执行后计算耗时并打印
                long end = System.nanoTime();
                System.out.println("cost time: " + (end - start));
            }
        }
    }
